﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mForum.Web.Common.Controllers
{
    using mForum.Core.Common;
    using mForum.Web.Common.ViewDataModel;
    using mForum.Web.Common.Infrastructure;

    [HandleError]
    public class HomeController : Controller
    {
        private IViewDataFactory _viewDataFactory;
        private ISessionManager _sessionManager;

        public HomeController(IViewDataFactory viewDataFactory, ISessionManager sessionManager)
        {
            Check.Argument.IsNotNull(viewDataFactory, "viewDataFactory");

            _viewDataFactory = viewDataFactory;
            _sessionManager = sessionManager;
        }

        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            _sessionManager.Set<string>("Message", "Testowa wiadomość przechowywana w sesji");

            BaseViewData view = _viewDataFactory.Create<HomeViewData>();
            return View(view);
        }

        public ActionResult About()
        {
            ViewData["Message"] = _sessionManager.TryGet<string>("Message");

            BaseViewData view = _viewDataFactory.Create<BaseViewData>();
            return View(view);
        }
    }
}
